home *** CD-ROM | disk | FTP | other *** search
- unit Gridsu;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, Grids, DBGrids, DB, DBTables, ExtCtrls, StdCtrls;
-
- type
- TForm1 = class(TForm)
- DataSource1: TDataSource;
- Table1: TTable;
- DBGrid1: TDBGrid;
- Table1CustNo: TFloatField;
- Table1Company: TStringField;
- procedure FormKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- {$B-}
- procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
-
- { Tabs are fine until we are at the last cell }
- { Are we at the last tab stop ? }
- function AtLastTabStop(G: TDBGrid): Boolean;
- var
- Loop: Word;
- begin
- Result := True;
- with G do
- begin
- if SelectedIndex = Pred(FieldCount) then
- Exit;
- for Loop := Succ(SelectedIndex) to Pred(FieldCount) do
- begin
- Result := Fields[Loop].ReadOnly;
- if not Result then
- Exit;
- end;
- end;
- end;
-
- procedure NextRecord(var Key: Word; DataSet: TDataSet);
- begin
- Key := 0;
- if not DataSet.EOF then
- DataSet.Next;
- end;
-
- begin
- if (ActiveControl is TDBGrid) and
- (TDBGrid(ActiveControl).DataSource <> nil) then
- case Key of
- vk_Tab: if not (ssShift in Shift) then
- with TDBGrid(ActiveControl).DataSource, DataSet do
- if AtLastTabStop(TDBGrid(ActiveControl)) then
- begin
- NextRecord(Key, DataSet);
- if not EOF then
- TDBGrid(ActiveControl).SelectedIndex := 0;
- end;
- vk_Down: if not (ssCtrl in Shift) then
- with TDBGrid(ActiveControl).DataSource, DataSet do
- NextRecord(Key, DataSet);
- else Exit;
- end;
- end;
-
- end.
-